﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Drawing.Printing;
using System.Drawing;

namespace receipt
{
    public class receiptClass
    {
        PrintDocument pdoc = null;
        int Amount, Payment;
        string Name, Grade, ID;
       
        public int curBal
        {
            set { this.Amount = value; }
            get { return this.Amount; }
        }
        public int payment
        {
            set { this.Payment = value; }
            get { return this.Payment; }
        }
        public string name
        {
            set { this.Name = value; }
            get { return this.Name; }
        }
        public string grade
        {
            set { this.Grade = value; }
            get { return this.Grade; }
        }
        public string id
        {
            set { this.ID = value; }
            get { return this.ID; }
        }

        public void print()
        {
            PrintDialog pd = new PrintDialog();
            pdoc = new PrintDocument();
            PrinterSettings ps = new PrinterSettings();
            Font font = new Font("Courier New", 6);
           
            PaperSize psize = new PaperSize("Custom", 140, 200);
            ps.DefaultPageSettings.PaperSize = psize;
            ps.DefaultPageSettings.Margins = new Margins(0,0,0,0);

            pd.Document = pdoc;
            pd.Document.DefaultPageSettings.PaperSize = psize;
            pd.Document.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);

            pd.PrinterSettings = ps;
          
            pdoc.PrintPage += new PrintPageEventHandler(pdoc_PrintPage);

            DialogResult result = pd.ShowDialog();
            if (result == DialogResult.OK)
            {
                PrintPreviewDialog pp = new PrintPreviewDialog();
                pp.Document = pdoc;
                result = pp.ShowDialog();
                if (result == DialogResult.OK)
                {
                    pdoc.Print();
                }
            }

        }
        void pdoc_PrintPage(object sender, PrintPageEventArgs e)
        {
            Graphics graphics = e.Graphics;
            int startX = 5;
            int startY = 5;
            int Offset = 40;
            graphics.DrawString("AGAPE LEARNING CENTER", new Font("Courier New", 6),
                                new SolidBrush(Color.Black), startX, startY + Offset);
            Offset = Offset + 8;
            Random r = new Random();
            graphics.DrawString("Receipt No: " + r.Next(1000, 9999).ToString(),
                     new Font("Courier New", 5),
                     new SolidBrush(Color.Black), startX, startY + Offset);

            Offset = Offset + 8;
            graphics.DrawString("Date :" + DateTime.Now.ToString(),
                     new Font("Courier New", 5),
                     new SolidBrush(Color.Black), startX, startY + Offset);

            Offset = Offset + 8;
            String underLine = "-----------------------------";
            graphics.DrawString(underLine, new Font("Courier New", 5),
                     new SolidBrush(Color.Black), startX, startY + Offset);


            Offset = Offset + 8;
            graphics.DrawString("Grade :" + this.grade,
                     new Font("Courier New", 5),
                     new SolidBrush(Color.Black), startX, startY + Offset);

            Offset = Offset + 8;
            graphics.DrawString("ID Number :" + this.id,
                     new Font("Courier New", 5),
                     new SolidBrush(Color.Black), startX, startY + Offset);

            Offset = Offset + 8;
            graphics.DrawString("Student Name :",
                     new Font("Courier New", 5),
                     new SolidBrush(Color.Black), startX, startY + Offset);
            Offset = Offset + 8;
            graphics.DrawString(this.name,
                     new Font("Courier New", 5),
                     new SolidBrush(Color.Black), startX, startY + Offset);


            Offset = Offset + 8;
            underLine = "-----------------------------";
            graphics.DrawString(underLine, new Font("Courier New", 5),
                     new SolidBrush(Color.Black), startX, startY + Offset);
           
            Offset = Offset + 8;
            graphics.DrawString("Transaction Bill:", new Font("Courier New", 5),
                     new SolidBrush(Color.Black), startX, startY + Offset);

            Offset = Offset + 8;
            String Current_Bal = "Current Balance: " + this.curBal;
            
            graphics.DrawString(Current_Bal, new Font("Courier New", 5),
                     new SolidBrush(Color.Black), startX, startY + Offset);

            Offset = Offset + 8;
            String Cash = "Payment: " + this.payment;

            graphics.DrawString(Cash, new Font("Courier New", 5),
                     new SolidBrush(Color.Black), startX, startY + Offset);

            Offset = Offset + 8;
            String Remaining_Bal = "Remaining Bal: " + (this.curBal - this.payment);

            graphics.DrawString(Remaining_Bal, new Font("Courier New", 5),
                     new SolidBrush(Color.Black), startX, startY + Offset);

           

        }
    }
}
